package com.moyun.zbmy.zizhou.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.moyun.zbmy.zizhou.R;
import com.moyun.zbmy.zizhou.beans.AccountBean;
import com.moyun.zbmy.zizhou.ui.adapter.MyAttentionAdapter;
import com.moyun.zbmy.zizhou.ui.utils.GlideCircleTransform;
import com.moyun.zbmy.zizhou.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 订阅号列表
 */
public class MyAttentionHolder extends BaseAbsHolder<AccountBean> implements View.OnClickListener {

    @BindView(R.id.account_img)
    protected ImageView account_img;
    @BindView(R.id.account_name)
    protected CustomFontTextView account_name;
    @BindView(R.id.account_news_content)
    protected CustomFontTextView account_news_content;
    @BindView(R.id.account_news_time)
    protected CustomFontTextView account_news_time;


    private AccountBean temp;
    private GlideCircleTransform circleTransform;
    private MyAttentionAdapter.OnAttentionClickListener listener;
    private OnAttentionItemClickListener itemClickListener;

    public MyAttentionHolder(Context context, View itemView,OnAttentionItemClickListener itemClickListener) {
        super(context, itemView);
        itemView.setOnClickListener(this);
        this.itemClickListener = itemClickListener;
    }


    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(AccountBean t) {
        temp = t;
        circleTransform = new GlideCircleTransform(context);
        account_name.setText(t.getFollowedName());
        if (!TextUtils.isEmpty(t.getDateString())) {
            String timeStr = DateUtils.formatDate(DateUtils.getDataDate(t), "");
            account_news_time.setText(timeStr);
        }else{
            account_news_time.setText("");
        }
        GlideUtil.getGlideWithSmall169DefCenterCrop(context, t.getDataImg()).into(account_img);
        if (!TextUtils.isEmpty(t.getFollowedMetaDescription())) {
            account_news_content.setText(t.getFollowedMetaDescription());
            account_news_content.setVisibility(View.VISIBLE);
        }else{
            account_news_content.setVisibility(View.GONE);
        }
        GlideUtil.getCircleGlid(context, t.getFollowedSmallImage(), true).diskCacheStrategy(DiskCacheStrategy.NONE).transform(circleTransform).into(account_img);
    }

    @Override
    public void setItemMode(int mode) {
        super.setItemMode(mode);

    }

    @Override
    public void onDestory() {
        super.onDestory();
        if (itemView != null) {
            itemView.setOnClickListener(null);
        }
    }

    @Override
    public void onClick(View v) {
        if (temp == null) {
            Toast.makeText(context, "数据错误", Toast.LENGTH_SHORT).show();
            return;
        }

        if(null!=itemClickListener){
            itemClickListener.OnAttentionItemClick(temp);
        }
    }

    public interface OnAttentionItemClickListener {
        void OnAttentionItemClick(AccountBean temp);
    }
}
